package cc.javaee.bbs.dao.activity;

import cc.javaee.bbs.dao.BaseDao;
import cc.javaee.bbs.model.Bankuai;
import cc.javaee.bbs.model.PageBean;
import cc.javaee.bbs.model.activity.KbrActivity;
import cc.javaee.bbs.params.DbResultMap;
import cc.javaee.bbs.params.WebParams;
import cc.javaee.bbs.tool.DataFormatUtil;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ActivityDao extends BaseDao {
	String ns="kbr_activity.";
	public List<KbrActivity> findpage(PageBean<KbrActivity> page) {
		int pageNo = page.getPageNo();
		List<KbrActivity> list=this.getSqlSession().selectList(ns+"findpage", page);
		if(list!=null&&list.size()>0){
			for (KbrActivity act : list) {
				act.setIndex(pageNo+1);
				act.setCreateTimeStr(DataFormatUtil.toTimeStrNull(act.getCreateTime()));
				act.setEnStartTimeStr(DataFormatUtil.toTimeStrNull(act.getEnStartTime()));
				act.setEnEndTimeStr(DataFormatUtil.toTimeStrNull(act.getEnEndTime()));
				act.setStartTimeStr(DataFormatUtil.toTimeStrNull(act.getStartTime()));
				act.setEndTimeStr(DataFormatUtil.toTimeStrNull(act.getEndTime()));
				pageNo++;
			}
		}
		return list;
	}
	public int findpagecount(PageBean<KbrActivity> page) {
		return this.getSqlSession().selectOne(ns+"findpagecount", page);
	}
	
	public List<KbrActivity> find(KbrActivity KbrActivity) {
		List<KbrActivity> list=this.getSqlSession().selectList(ns+"find", KbrActivity);
		if(list!=null&&list.size()>0){
			for (KbrActivity act : list) {
				act.setCreateTimeStr(DataFormatUtil.toTimeStrNull(act.getCreateTime()));
				act.setEnStartTimeStr(DataFormatUtil.toTimeStrNull(act.getEnStartTime()));
				act.setEnEndTimeStr(DataFormatUtil.toTimeStrNull(act.getEnEndTime()));
				act.setStartTimeStr(DataFormatUtil.toTimeStrNull(act.getStartTime()));
				act.setEndTimeStr(DataFormatUtil.toTimeStrNull(act.getEndTime()));
			}
		}
		return list;
	}

	public void insert(KbrActivity KbrActivity) {
		this.getSqlSession().insert(ns+"insert", KbrActivity);
	}

	public void delete(Integer id) {
		this.getSqlSession().delete(ns+"delete", id);
	}

	public List<DbResultMap> findDbList(WebParams param) {
		List<DbResultMap> list=this.getSqlSession().selectList(ns+"findDb", param);
		if(list!=null&&list.size()>0){
			for (DbResultMap act : list) {
				act.put("enStartTimeStr",DataFormatUtil.toDateStrNull(act.getDate("enStartTime")));
				act.put("enEndTimeStr",DataFormatUtil.toDateStrNull(act.getDate("enEndTime")));
				act.put("startTimeStr",DataFormatUtil.toDateStrNull(act.getDate("startTime")));
				act.put("endTimeStr",DataFormatUtil.toDateStrNull(act.getDate("endTime")));
			}
		}
		return list;
	}
	
	public DbResultMap findDb(WebParams param) {
		DbResultMap db=new DbResultMap();
		List<DbResultMap> list=this.getSqlSession().selectList(ns+"findDb", param);
		if(list!=null&&list.size()>0){
			for (DbResultMap act : list) {
				act.put("enStartTimeStr",DataFormatUtil.toDateStrNull(act.getDate("enStartTime")));
				act.put("enEndTimeStr",DataFormatUtil.toDateStrNull(act.getDate("enEndTime")));
				act.put("startTimeStr",DataFormatUtil.toDateStrNull(act.getDate("startTime")));
				act.put("endTimeStr",DataFormatUtil.toDateStrNull(act.getDate("endTime")));
				db=act;
				break;
			}
		}
		return db;
	}
	
	public void updateByDb(KbrActivity kbrActivity) {
		this.getSqlSession().update(ns+"updateByDb", kbrActivity);
	}
	public void updateByParam(WebParams param) {
		this.getSqlSession().update(ns+"updateByDb", param);
	}
	
	public void update(KbrActivity KbrActivity) {
		this.getSqlSession().update(ns+"update", KbrActivity);
	}
	
	public Integer getMaxId(WebParams param) {
		Integer aaa=(Integer) this.getSqlSession().selectOne(ns+"getMaxId", param);
		return aaa;
	}
}